package top.haichi.webpaper.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import top.haichi.webpaper.Interceptors.*;

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Autowired
    private UserLoginInterceptor userLoginInterceptor;
    @Autowired
    private StudentInterceptor studentInterceptor;
    @Autowired
    private FileUploadInterceptor fileUploadInterceptor;
    @Autowired
    private CorsInterceptor corsInterceptor;
    @Autowired
    private TeacherInterceptor teacherInterceptor;
    @Autowired
    private AdminInterceptor adminInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        registry.addInterceptor(corsInterceptor)
                        .addPathPatterns("/**");

//        user登录拦截器
        registry.addInterceptor(userLoginInterceptor)
                .addPathPatterns("/user/**")
                .excludePathPatterns("/user/login")
                .excludePathPatterns("/user/register");

        //student拦截器
        registry.addInterceptor(studentInterceptor)
                .addPathPatterns("/student/**");

        //teacher拦截器
        registry.addInterceptor(teacherInterceptor)
                .addPathPatterns("/teacher/**");

        //fileUpload拦截器
        registry.addInterceptor(fileUploadInterceptor)
                .addPathPatterns("/file/upload/**");

        //admin拦截器
        registry.addInterceptor(adminInterceptor)
                .addPathPatterns("/admin/**");

    }
}
